﻿using UnityEngine;
using System.Collections;

public class Entity : MonoBehaviour
{

    public float totalHP = 100;
    
    public float damage = 10;
    public string type = "Entity";
    
    protected int kind = GameConfig.PLAYER;
    protected float currentHP = 10;
    protected bool isInit = false;

    public delegate void EntityEvent(object obj);

    public event EntityEvent onHurt = null;
    public event EntityEvent onDie = null;




    public Entity() {
        currentHP = totalHP;
    }

    public float getCurrentHP() {
        return currentHP;
    }
    public void setKind(int kind)
    {
        this.kind = kind;
    }

    public int getKind()
    {
        return kind;
    }

    public virtual void hurt(float damage)
    {
        currentHP -= damage;

        if(onHurt != null){
            onHurt.Invoke(damage);
        }

        if (currentHP <= 0)
        {
            die();
        }
    }

    public virtual void die()
    {
        if (onDie != null) {
            onDie.Invoke(null);
        }
    }
}
